package com.woniuxy.service.impl;

import com.woniuxy.entity.ProductSpecRelations;
import com.woniuxy.dao.ProductSpecRelationsDao;
import com.woniuxy.entity.ShopSpecOptions;
import com.woniuxy.service.ProductSpecRelationsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;


/**
 * (ProductSpecRelations)表服务实现类
 *
 * @author makejava
 * @since 2025-07-15 17:07:14
 */
@Service("productSpecRelationsService")
public class ProductSpecRelationsServiceImpl implements ProductSpecRelationsService {
    @Autowired
    private ProductSpecRelationsDao productSpecRelationsDao;
    @Override
    public ProductSpecRelations findByOptId(Integer optId) {
        return productSpecRelationsDao.findByOptId(optId);
    }

    /**
     * 通过ID查询单条数据
     *
     * @param relId 主键
     * @return 实例对象
     */
    @Override
    public ProductSpecRelations queryById(Integer relId) {
        return this.productSpecRelationsDao.queryById(relId);
    }

    /**
     * 分页查询
     *
     * @param productSpecRelations 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<ProductSpecRelations> queryByPage(ProductSpecRelations productSpecRelations, PageRequest pageRequest) {
        long total = this.productSpecRelationsDao.count(productSpecRelations);
        return new PageImpl<>(this.productSpecRelationsDao.queryAllByLimit(productSpecRelations, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param productSpecRelations 实例对象
     * @return 实例对象
     */
    @Override
    public ProductSpecRelations insert(ProductSpecRelations productSpecRelations) {
        this.productSpecRelationsDao.insert(productSpecRelations);
        return productSpecRelations;
    }

    /**
     * 修改数据
     *
     * @param productSpecRelations 实例对象
     * @return 实例对象
     */
    @Override
    public ProductSpecRelations update(ProductSpecRelations productSpecRelations) {
        this.productSpecRelationsDao.update(productSpecRelations);
        return this.queryById(productSpecRelations.getRelId());
    }

    /**
     * 通过主键删除数据
     *
     * @param relId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer relId) {
        return this.productSpecRelationsDao.deleteById(relId) > 0;
    }
}
